package com.spring.test.config;

//import com.itcast.springboot.pojo.RespBean;
import com.spring.test.dao.RespBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理
 */
@RestControllerAdvice("com.itcast.springboot")
public class ControllerExceptionAdvice {

    final static Logger logger = LoggerFactory.getLogger(ControllerExceptionAdvice.class);

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public RespBean exceptionHandler(Exception e) {

        logger.error("",e);
        return RespBean.fail();
    }

    @ExceptionHandler(BusinessException.class)
    @ResponseBody
    public RespBean exceptionHandler(BusinessException e) {
        logger.error("",e);
        return RespBean.fail();
    }


}

